<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>膜丝抽检</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
	<style type="text/css">
		.layui-form-item {
			display: inline-block;
			width: 30%;
		}
		.layui-table-cell {
			overflow:visible;
		}
		#details form .layui-input {
			border-top:none;
			border-left:none;
			border-right:none;
			/* border-bottom:1px solid #AAA !important; */
			background-color: rgb(242,242,242);
			border-radius:0;
		}
	</style>
</head>
<body>
<!-- 顶部搜索：一个条码框，一个按钮（可无） -->
<div class="" style="margin:10px 0 0 15px;width: 98%">
    <!-- 
	    <div class="layui-inline">
	        <input style="width: 350px;height: 38px;font-size: 18px;padding-right: 40px;" value="" class="layui-input" id="code" placeholder="条形码" autocomplete="off">
	    </div>
	    &emsp;&emsp;&emsp;&emsp; 
    -->
    <div class="layui-inline">
        <input class="layui-input" style="font-size: 18px;width: 350px" name="click_keyword" id="click_keyword"  placeholder="点击查看待检列表" autocomplete="off">
    </div>
    <button class="layui-btn layui-btn-blue" onclick="search()" style="margin: 0 0 0 10px;" data-type="reload"><i class="layui-icon layui-icon-search">搜索</i></button>
</div>
<!-- 疑似不良品信息 及操作 -->
<div id="details" style="margin:10px 0 0 0;/* display:none; */background-color:rgb(242,242,242);border-top:#e6e6e6 1px solid" hidden>
    <div>
    	<table class="layui-table">
    		<thead>
    			<tr>
    				<th colspan="4"><h2 style="text-align: center;">膜丝抽检单信息</h2></th>
    				<th><input type="hidden" id="checkListId"></th>
    			</tr>
    		</thead>
    		<tbody>
    			<tr>
    				<td width="20%">膜丝捆编号</td>
    				<td><input readonly class="layui-input" id="mbcode"/></td>
    				<td width="20%">膜丝根编号</td>
    				<td><input readonly class="layui-input" id="mscode"/></td>
    			</tr>
    			<tr>
    				<td width="20%">生产计划单</td>
    				<td><input readonly class="layui-input" id="msplan"/></td>
    				<td width="20%">操作人</td>
    				<td><input readonly class="layui-input" id="msoperator"/></td>
    			</tr>
    			<tr>
    				<td width="20%">操作时间</td>
    				<td><input readonly class="layui-input" id="mstime"/></td>
    			</tr>
    		</tbody>
    	</table>
    	
    	<form class="layui-form layui-card-body">
	   		<table class="layui-table" id="myTable">
    		<thead>
    			<tr>
    				<th colspan="9"><h2 style="text-align: center;">膜丝抽检</h2></th>
    			</tr>
    			<tr>
	   				<th>样本序号</th>
	   				<th>膜丝编号</th>
	   				<th>通量（LMH）</th>
	   				<th>内径（mm）</th>
	   				<th>壁厚（mm）</th>
	   				<th>泡点压力（Mpa）</th>
	   				<th>强度（g）</th>
	   				<th>结果</th>
	   			</tr>
    		</thead>
    		<tbody id="tbody">
    			<tr>
    				<td align="center">1</td>
    				<td><input class="layui-input"/></td>
    				<td><input class="layui-input"/></td>
    				<td><input class="layui-input"/></td>
    				<td><input class="layui-input"/></td>
    				<td><input class="layui-input"/></td>
    				<td><input class="layui-input"/></td>
    				<td><input class="layui-input"/></td>
    			</tr>
    		</tbody>
    		<tfoot>
    			<tr>
    				<td colspan="9" align="center">
    					<input style="font-size: 30px" type="button" class="layui-btn" id="add" value="＋">
    					<input style="font-size: 30px" type="button" class="layui-btn" id="recover" value="－">
    				</td>
    			</tr>
    		</tfoot>
    	</table>
	   		<div class="layui-form-item">
		   		<div class="" style="margin:10px 0 0 20px">
			  		<input class="layui-btn layui-btn-blue" type="button" style="padding: 0 30px" onclick = "save()" value="保存">
				</div>
			</div>
	   	</form>
    </div>
</div>
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
<script type="text/javascript">
	$(function(){
		$("#click_keyword").click(function(){
			/* ——————————————————————分页弹框——————————————————————— */
			layui.use(['table','layer','upload','form','laydate'], function(){
				var table = layui.table;
				var layer = layui.layer;
			    var form = layui.form;

			    var $ = layui.jquery, active = {
					reload:function () {
						/*var searchTime = $("#searchTime").val();*/
						var keyword01 = $("#keyword").val();
						/*console.log(searchTime + ',' + keyword)*/
						table.reload('contenttable',{
							method:'get',
							where:{"keyword01":keyword01},
							page: {
								curr: 1
							}
						});
					}
				}
				$('.layui-btn').on('click', function(){
			        var type = $(this).data('type');
			        active[type] ? active[type].call(this) : '';
			    });
			    var content = '<div id="hideDv" style="padding:10px 0 0 15px">'+
									'<div class="layui-inline">'+
									'<input class="layui-input" name="keyword" id="keyword" placeholder="请输入膜丝根编号" autocomplete="off" style="display: inline; width: 100%">'+
								'</div>'+
								'<button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">搜索</i></button>'+
								'<table class="layui-hide" id="tableList" lay-filter="tableList"></table>'+
							'</div>'
			    layer.open({
			        type: 1 					//Page层类型
			        ,area: ['900px', '450px']   //宽  高
			        ,title: '膜丝抽检'
			        ,shade: 0.6 				//遮罩透明度
			        ,maxmin: true 			    //允许全屏最小化
			        ,anim: 1 					//0-6的动画形式，-1不开启
			        ,content: content
			        /* ,content: $('#tableList') */
			        ,success: function(){
			            layui.use(['table'], function() {
			                var table = layui.table;
			                table.render({
			                    elem: '#tableList'
			                    ,url:'${pageContext.request.contextPath }/processItem/queryMembraneFilaments.do'
			                    /*,where:{dId:thisRowId.id}*/
			                    /*,toolbar: '#toolbar'*/
			                    ,title: '膜丝抽检'
			                    ,id :'contenttable'
			                    ,limits:[10,20,30]
			                    ,cols: [[
			                        /*{type: 'checkbox', fixed: 'left'},*/
			                        {field:'', title:'序号', sort: true, type:'numbers', width: 60},
			                        {field:'mbcode', title:'膜丝(捆)编号', align: 'center'},
			                        {field:'mscode', title:'膜丝(根)编号', align: 'center'},
			                        {field:'msplan', title:'生产计划单', align: 'center'},
			                        {field:'msoperator', title:'报检人', align: 'center'},
			                        {field:'mstime', title:'报检时间', align: 'center'},
			                    ]]
			                    ,page: true
			                });
			                table.on('rowDouble(tableList)', function(obj){
			                    var number = obj.data.mscode;
			                    $("#click_keyword").val(number);
			                    //给'膜丝抽检单信息'赋值
			                    //报检单ID(隐藏域)
			                    $("#checkListId").val(obj.data.msid);
			                    
			                    $("#mbcode").val(obj.data.mbcode);
			                    $("#mscode").val(number);
			                    $("#msplan").val(obj.data.msplan);
			                    $("#msoperator").val(obj.data.msoperator);
			                    $("#mstime").val(obj.data.mstime);
			                    layer.closeAll();
			                 });
			            });
			        },
			        end: function(){
			        	$('#hideDv').hide();
			        }
			    });
			});
		});
		
		//点击'+''-'的效果
		var index;
		$("#add").click(function(){
			var tbody = document.getElementById("tbody");
			index = tbody.rows.length + 1
			$("#tbody").append(
					'<tr id="tr'+index+'">'+
						'<td align="center">'+index+'</td>'+
						'<td><input class="layui-input"/></td>'+
						'<td><input class="layui-input"/></td>'+
						'<td><input class="layui-input"/></td>'+
						'<td><input class="layui-input"/></td>'+
						'<td><input class="layui-input"/></td>'+
						'<td><input class="layui-input"/></td>'+
						'<td><input class="layui-input"/></td>'+
					'</tr>'
				)
		})
		$("#recover").click(function(){
			var tbody = document.getElementById("tbody");
			var curr = tbody.rows.length
			document.getElementById('tbody').deleteRow(curr-1);
		})
	})
	
	//点击'搜索'按钮
	function search(){
		$("#details").show();
	}
	//保存订单结果
	function save(){
		var orderNumber = "MS"+(new Date()).getTime();
		var checkListId = $("#checkListId").val();
		var mbcode = $("#mbcode").val();
		var mscode = $("#mscode").val();
		var msplan = $("#msplan").val();
		var msoperator = $("#msoperator").val();
		var mstime = $("#mstime").val();
		/* 
			var msName = $("#msName").val();
			var msStandard = $("#msStandard").val();
			var checkBatch = $("#checkBatch").val(); 
		*/
		var checkStatus = "0";
		$.ajax({
			type:'post'
			,url:'${pageContext.request.contextPath }/msSpotCheck/insertMsSpotCheck.do'
			,data:{orderNumber:orderNumber, checkListId:checkListId, mbcode:mbcode, mscode:mscode, msplan:msplan,msoperator:msoperator, mstime:mstime}
			,dataType:'json'
			,success:function(res){
				if(res>0){
					$("#tbody tr").each(function(i,dom){
						var tr = $(dom).closest("tr");
						var tds = tr.find("td");
						var msNumber = tds[1].getElementsByTagName("input")[0].value;
						var msFlux  = tds[2].getElementsByTagName("input")[0].value;
						var msInner = tds[3].getElementsByTagName("input")[0].value;
						var msWall = tds[4].getElementsByTagName("input")[0].value;
						var msBubble = tds[5].getElementsByTagName("input")[0].value;
						var msIntensity = tds[6].getElementsByTagName("input")[0].value;
						var msResult = tds[7].getElementsByTagName("input")[0].value;
						/* var tResult = tds[6].getElementsByTagName("select")[0].value; */
						$.ajax({
							type:'post'
							,url:'${pageContext.request.contextPath }/msSpotCheck/insertMsSpotCheckDetails.do'
							,data:{orderNumber:orderNumber,msNumber:msNumber,msFlux:msFlux,msInner:msInner,msWall:msWall,msBubble:msBubble,msIntensity:msIntensity,msResult:msResult}
							,dataType:'json'
							,success:function(data){
								
							}
						})
					});
					toastr.success("保存成功！");
					setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
						window.location.reload();  
					},2000);
				}else{
					toastr.error("保存失败！");
				}
			}
		})
	}
	toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
</script>
</body>
</html>